const crypto = require('crypto-js');

function enc(){
    var key= crypto.enc.Utf8.parse('12345678'),
    iv= crypto.enc.Utf8.parse('12345678'),
    data=crypto.enc.Utf8.parse('python');//数据加密之前一般先进行编码 
    crypto_text = crypto.DES.encrypt(data,key,{
        iv:iv,
        mode:crypto.mode.CBC,
        padding:crypto.pad.Pkcs7
    })
    return crypto_text.toString();
}

function dec(data){
    var key= crypto.enc.Utf8.parse('12345678'),
    iv= crypto.enc.Utf8.parse('12345678'),
    data=data;//数据解密，密文不用进行编码
    crypto_text = crypto.DES.decrypt(data,key,{
        iv:iv,
        mode:crypto.mode.CBC,
        padding:crypto.pad.Pkcs7
    })  
    return crypto_text.toString(crypto.enc.Utf8);
}   

console.log(dec(enc())); 